package com.example.myblog.service;

import cn.hutool.db.PageResult;
import com.example.myblog.dao.ColumnistMapper;
import com.example.myblog.entity.Columnist;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TypeService {
    @Autowired
    private ColumnistMapper typeMapper;
    /**增*/
    public int addType(Columnist columnist){
        return typeMapper.addColumnist(columnist);
    }
    /**分页查询当前page*/
    public Page<Columnist> listType(int page) {
        PageHelper.startPage(page,3);
        return typeMapper.listType();
    }
    /**删*/
    public int deleteById(int id){
        return typeMapper.deleteColumnistById(id);
    }
    /**根据id查找*/
    public Columnist findById(int id){
        return typeMapper.findColumnistById(id);
    }
    /**更新分类*/
    public int update(Columnist columnist){
        return typeMapper.updateColumnist(columnist);
    }
    /**根据name查找*/
    public Columnist getTypeByName(String colName){
        HashMap<String,Object> map = new HashMap<>();
        map.put("colName",colName);
        return typeMapper.findColumnistByCondition(map);
    }
    /**查询所有分类--list*/
    public List<Columnist> list (){
        return typeMapper.findColumnistAll();
    }
    /**查询前num个--list*/
    public List<Columnist> listTopNum(Integer num){
        return typeMapper.findColumnistTopNum(num);
    }
}
